<#-- @ftlvariable name="layoutFields" type="java.util.List<com.fable.sp.core.domain.PersistentField>" -->
<@ui.html>
<#assign fs = RequestParameters.formField/>
<table class="table table-bordered">
    <tr>
        <th></th>
        <th>域名</th>
        <th>描述</th>
    </tr>
    <#list layoutFields as field>
        <tr>
            <td><input type="checkbox" name="fieldName" data-value="${field.name}" class="field-checkbox" <#if fs?contains(field.name)>checked="checked"</#if></td>
            <td>${field.name}</td>
            <td>${field.display}</td>
        </tr>
    <#else >
        <tr>
            <td colspan="3" class="text-center">暂无域纪录</td>
        </tr>
    </#list>
</table>
    <#if layoutFields?has_content>
    <div class="text-center">
        <button type="button" class="btn btn-primary" id="chooseFields">选取</button>
    </div>
    </#if>
<script>
    $(function () {
        var info = SP.infoModal("请至少选中一个域");
        $("#chooseFields").click(function () {
            var fieldNames = $(".field-checkbox:checked").map(function () {
                return $(this).attr("data-value");
            }).get();
            if (fieldNames && fieldNames.length > 0) {
                var opener = window.opener || parent;
                if (opener && opener.onFieldSelected) {
                    opener.onFieldSelected(fieldNames);
                }
            } else {
                info.modal("show");
            }
        })
    });
</script>
</@ui.html>